package servlet;

import java.io.IOException;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Random;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dao.OrderMasterDao;
import dao.impl.OrderMasterDaoImpl;
import entity.Order_Master;
import util.PayUtil;


public class GoToPayServlet extends HttpServlet {
	private OrderMasterDao omd = new OrderMasterDaoImpl();
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        PayUtil payUtil = new PayUtil();
		int i = (int)(Math.random()*900+100);
		String a = Integer.toString(i);
		String options = request.getParameter("options");
		String money = request.getParameter("money");
		String addr = request.getParameter("addr");
		StringBuffer sb = new StringBuffer();
		Calendar cal = Calendar.getInstance();
		 Random random = new Random();
		boolean flag = true;
		Integer month = cal.get(Calendar.MONTH)+1;
		Integer day = cal.get(cal.DAY_OF_MONTH);
		String string = month.toString();
		if(string.length()==1){
				string = "0"+string;
		}
		sb.append("19");
		sb.append(string);
		sb.append(day);
		sb.append(a);
		payUtil.setOrder_sn(Integer.parseInt(sb.toString()));
		payUtil.setPrice(Double.parseDouble(money));
		payUtil.setExpress_company(options);
		request.getSession().setAttribute("pay", payUtil);
		
		request.getRequestDispatcher("/alibaba/index.jsp").forward(request, response);
			
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
